<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	
		<a href="http://www.taobao.com">淘宝</a>
		<a href="#123">#123</a>
		<a href="#456">#456</a>
		<a href="#/">首页</a>
		<a href="#/about">about</a>
		<a href="?id=123">query123</a>
		<div class="routerView"></div>
		<script type="text/javascript">
			// #hash
			
			let routerView = [
				{
					path:"/",
					content:"<div>这是首页</div>"
				},{
					path:"/about",
					content:"<div>这是ABOUT</div>"
				}	
			
			]
			window.addEventListener('hashchange',()=>{
				console.log('hash:',location.hash)
				console.log(location)
				if(!location.hash){
					location.hash = "#/"
				}else{
					RouterRender(location.hash)
				}
				
			})
			if(!location.hash){
				location.hash = "#/"
			}
			RouterRender(location.hash)
			
			function RouterRender(url){
				let resContent = "<h1>404 not fond</h1>";
				routerView.forEach((item,i)=>{
					if(url==('#'+item.path)){
						resContent = item.content;
					}
				})
				let divRouterview =document.querySelector('.routerView')
				divRouterview.innerHTML = resContent;
			}
		</script>
	</body>
</html>
